var v = new Vue({
	el:"#delivery",
	data:{
		vdata:{},
		selected:'',
        lossNum:0,
        memo:""
	},
	methods:{
		getList: function() {
            var _this = this;
            $.get(
                "/index.php/Order/getNodelivery",
                function(ret) {
                    if (ret.status == "success") {
                        _this.vdata = ret.data.data;
                        //console.log( ret.data);
                        var show=1;
                        if(ret.data.totalPage < 5){
                                    show = ret.data.totalPage;
                                }else{
                                    show = 5;
                                }
                        $(".page").twbsPagination({
                                totalPages: ret.data.totalPage,
                                visiblePages: show,
                                onPageClick: function(event, page) {
                                    $.post(
                                        "/index.php/Order/getNodelivery", {
                                            page: page
                                        },
                                        function(reg) {
                                            if(reg.status == "success"){
                                                _this.vdata = reg.data.data;
                                            }
                                        }
                                    );
                                }
                            });
                    } else {
                        layer.msg("还没有记录!",{icon:2});
                    }
                }
            );
        },
        type:function(id){
            if(this.selected == 1){
                this.delivery(id);
            }else if(this.selected == 2){
                this.finished(id);
            }else if(this.selected == 3){
                layer.open({
                  type: 2,
                  title: '填写损耗页面',
                  shadeClose: true,
                  shade: 0.8,
                  area: ['80%', '60%'],
                  content: '/index.php/Order/CompLoss?id='+id+"&status="+this.selected //iframe的url
                });
                //this.cancel(id);
            }else if(this.selected == 4){

            }else if(this.selected == 5){
                layer.open({
                  type: 2,
                  title: '填写损耗页面',
                  shadeClose: true,
                  shade: 0.8,
                  area: ['80%', '60%'],
                  content: '/index.php/Order/CompLoss?id='+id+"&status="+this.selected //iframe的url
                });

            }
        },
        delivery:function(id){
            //发货
            $.post(
                "/index.php/Order/editStatus",
                {
                    id:id,
                    status:1
                },
                function(ret){
                    if(ret.status == "success"){
                        layer.msg(ret.data,{icon:1});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);
                    }else{
                        layer.msg(ret.data,{icon:2});
                    }
                }
            );
        },
        finished:function(id){
            //订单完成
            console.log(id);
            $.post(
                "/index.php/Order/editStatus",
                {
                    id:id,
                    status:3,
                    loss:v.lossNum

                },
                function(ret){
                    if(ret.status == "success"){
                        layer.msg(ret.data,{icon:1});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);
                    }else{
                        layer.msg(ret.data,{icon:2});
                    }
                }
            );
        },
        cancel:function(id){
             //取消订单
            if(this.memo == ""){
                layer.msg("取消订单备注不能为空");
            }else{
                $.post(
                    "/index.php/Order/editStatus",
                    {
                        id:id,
                        status:4,
                        memo:v.memo
                    },
                    function(ret){
                        if(ret.status == "success"){
                            layer.msg(ret.data,{icon:1});
                            setTimeout(function(){
                                parent.location.reload();
                            },1000);
                        }else{
                            layer.msg(ret.data,{icon:2});
                        }
                    }
                );
            }
           
            
        },
        CompLoss:function(id){
            //完成时有损耗
            if(v.memo == ""){
                layer.msg("请备注损耗的原因");
            }else{
                $.post(
                    "/index.php/Order/editStatus",
                    {
                        id:id,
                        status:3,
                        loss:v.lossNum,
                        memo:v.memo
                    },
                    function(ret){
                        if(ret.status == "success"){
                            layer.msg(ret.data,{icon:1});
                            setTimeout(function(){
                                parent.location.reload();
                            },1000);
                        }else{
                            layer.msg(ret.data,{icon:2});
                        }
                    }
                );
            }
            
        }
	},
	ready: function() {
        this.getList();
    }
});